package com.powazi.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

import com.powazi.logging.service.LogService;
import com.powazi.model.logging.LogModel;

@Aspect
public class ActionAspect {

	/**
	 * Defined in spring-aop.xml.<BR>
	 */
	@Pointcut("execution(* com.powazi.ums.web.action..*.execute())")
	public void umsActionPointcut() {

	}

	// @Before("umsActionPointcut()")
	// public void beforeAction() {
	// System.out.println("AOP : Before
	// Action====================================");
	// }

	@Around("com.powazi.aop.ActionAspect.umsActionPointcut()")
	public String aroundAction(ProceedingJoinPoint pjp) throws Exception {
		System.out.println("AOP : Around Action  =============");
		LogModel log = new LogModel();
		try {

			pjp.getTarget();
			String returnString = (String) pjp.proceed();

			this.logService.log(log);
			return returnString;

		} catch (Exception e) {
			this.logService.logException(log, e);
			throw e;
		} catch (Throwable e) {
			this.logService.logException(log, e);
			e.printStackTrace();
		}
		return "";
	}

	// @After("umsActionPointcut()")
	// public String aroundAction(Joinpoint jp) throws Exception {
	// System.out.println("AOP : Around Action =============");
	// LogModel log = new LogModel();
	// try {
	//
	// // pjp.getTarget();
	//
	// this.logService.log(log);
	// return "";
	//
	// } catch (Exception e) {
	// this.logService.logException(log, e);
	// throw e;
	// }
	//
	// }

	protected LogService logService;

	public LogService getLogService() {
		return logService;
	}

	public void setLogService(LogService logService) {
		this.logService = logService;
	}
}
